home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CWASTEDlgText.cpp
-
- A class with some of the functionality of CDialogText, but using CWASTEText
-
- by Dan Crevier
- version 1.8
-
- Roms 95/11/08 adapted to THINK C / TCL 1.1.3
- ******************************************************************************/
-
- #ifdef TCL_PCH
- #include <TCLHeaders>
- #endif
-
- #include "CWASTEDlgText.h"
- #include "CDialog.h"
- #include <CPaneBorder.h>
- #include "CBartender.h"
- #include "Constants.h"
- #include "CTextEditTask.h"
-
- #define kBorderAmount 2 // white space between border and text of edit field
-
- extern CBartender *gBartender;
- extern CBureaucrat *gGopher; // First in line to get commands
-
- static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
- long inputAreaEnd, long pinRangeStart, long pinRangeEnd);
-
- #if TCL_VERSION >= 0x02000000
- TCL_DEFINE_CLASS_D1(CWASTEDlgText, CWASTEText);
- #endif
-
- #ifndef THINK_C
- /********************************************************\
- CWASTEDlgText - default constructor
- \********************************************************/
-
- CWASTEDlgText::CWASTEDlgText()
- {
- TCL_END_CONSTRUCTOR
- }
-
-
- /********************************************************\
- CWASTEDlgText - constructor
- \********************************************************/
-
- CWASTEDlgText::CWASTEDlgText(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- short aLineWidth,
- Boolean aScrollHoriz,
- Boolean aIsRequired,
- long aMaxValidLength,
- Boolean aValidateOnResign,
- Boolean supportObjects,
- Boolean supportUndo,
- Boolean supportDragAndDrop,
- Boolean outlineHighliting,
- Boolean drawOffscreen)
-
- : CWASTEText(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl,
- aHSizing, aVSizing, aLineWidth, aScrollHoriz, NULL, supportObjects,
- supportUndo, supportDragAndDrop, outlineHighliting, drawOffscreen)
- {
-
- IWASTEDlgTextX();
- TCL_END_CONSTRUCTOR
- }
-
-
- /********************************************************\
- ~CWASTEDlgText - destructor
- \********************************************************/
-
- CWASTEDlgText::~CWASTEDlgText()
- {
- TCL_START_DESTRUCTOR
- }
-
- #endif // THINK_C
-
- /********************************************************\
- IWASTEDlgText - initializer, if used with default
- constructor
- \********************************************************/
-
- void CWASTEDlgText::IWASTEDlgText(CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing, SizingOption aVSizing,
- short aLineWidth)
- {
-
- CWASTEText::IWASTEText(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl,
- aHSizing, aVSizing, aLineWidth
- #ifdef THINK_C
- ,
- NULL,
- true,
- true,
- true,
- true,
- false
- #endif // THINK_C
- );
-
- IWASTEDlgTextX();
- }
-
-
- /********************************************************\
- IViewTemp - construct from View resource
- \********************************************************/
-
- void CWASTEDlgText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
- Ptr viewData)
- {
- CWASTEText::IViewTemp(anEnclosure, aSupervisor, viewData);
-
- IWASTEDlgTextX();
- }
-
-
- /********************************************************\
- IWASTEDlgTextX - common initialization
- \********************************************************/
-
- void CWASTEDlgText::IWASTEDlgTextX()
- {
- #if WASTE_VERSION >= 0x01100000
- static WETSMPostUpdateUPP postProc = NULL;
- #else
- WETSMPostUpdateProcPtr postProc;
- #endif
-
- MakeBorder();
- SetWholeLines(FALSE);
-
- // set postupdate routine to WEPostUpdate
- #if WASTE_VERSION >= 0x01100000
- if (postProc == NULL)
- postProc = NewWETSMPostUpdateProc(WEPostUpdate);
- #else
- postProc = &WEPostUpdate;
- #endif
- WESetInfo(weTSMPostUpdate, (Ptr)&postProc, macWE);
- }
-
- /********************************************************\
- WEPostUpdate -- broadcast a dialog text changed message
- \********************************************************/
-
- pascal void CWASTEDlgText::WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
- long inputAreaEnd, long pinRangeStart, long pinRangeEnd)
- {
- short ID;
- GrafPtr curPort;
- CWASTEText *itsOwner = NULL;
-
- WEGetInfo(weRefCon, (Ptr)&itsOwner, hWE);
- #if TCL_VERSION >= 0x02000000
- TCL_ASSERT_OBJECT_PTR(itsOwner);
- TCL_ASSERT(member(itsOwner, CWASTEText));
- #else
- ASSERT(member(itsOwner, CWASTEText));
- #endif
-
- CWASTEText::WEPostUpdate(hWE, fixLength, inputAreaStart, inputAreaEnd, pinRangeStart,
- pinRangeEnd);
-
- if (itsOwner != NULL)
- {
- GetPort(&curPort);
- ID = itsOwner->ID;
- itsOwner->BroadcastChange(dialogTextChanged, &ID);
- SetPort(curPort);
- itsOwner->Prepare();
- }
- }
-
-
- /********************************************************\
- MakeBorder - put a border around the text
- \********************************************************/
-
- void CWASTEDlgText::MakeBorder()
- {
- Rect margin;
- CPaneBorder *border;
-
- #if TCL_VERSION >= 0x02000000
- border = TCL_NEW(CPaneBorder,());
- #else
- border = new (CPaneBorder);
- #endif
-
- border->IPaneBorder(kBorderFrame);
- SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
- border->SetMargin(&margin);
- SetBorder(border);
- }
-
- /********************************************************\
- DoKey - handle Tab and Return
- \********************************************************/
-
- void CWASTEDlgText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
- {
- Boolean pass = TRUE;
- short ID;
-
- switch (theChar)
- {
- case '\t':
- case '\r':
- case kEnterKey:
- pass = FALSE;
- break;
-
- case kEscapeOrClear:
- if (keyCode == KeyEscape) pass = FALSE;
- break;
- }
- if (pass)
- {
- CWASTEText::DoKeyDown(theChar, keyCode, macEvent);
-
- #if WASTE_VERSION >= 0x01100000
- { // I'm not sure of the right thing to do here -- check mod counts?
- #else
- if (itsTypingTask && itsTypingTask->CanStillType())
- {
- #endif
- ID = this->ID;
- BroadcastChange(dialogTextChanged, &ID);
- }
- }
- else
- itsSupervisor->DoKeyDown(theChar, keyCode, macEvent);
- }
-
- /********************************************************\
- GetTextString - return the text as a pascal string
- \********************************************************/
-
- void CWASTEDlgText::GetTextString(StringPtr aString)
- {
- short length = Min(GetLength(), 255);
-
- StopInlineSession();
- BlockMove(*GetTextHandle(), &aString[1], length);
- aString[0] = length;
- }
-
- /********************************************************\
- PerformEditCommand - handle cut, copy, paste, and clear
- -- check for text changed
- \********************************************************/
-
- void CWASTEDlgText::PerformEditCommand(long theCommand)
- {
- short ID;
-
- CWASTEText::PerformEditCommand(theCommand);
-
- switch( theCommand)
- {
- case cmdCut:
- case cmdPaste:
- case cmdClear:
- ID = this->ID;
- BroadcastChange(dialogTextChanged, &ID);
- break;
-
- default:
- break;
- }
-
- }
-
- #if VA_COMPATIBLE_IO
-
- /******************************************************************************
- PutTo
- Put the contents of this object to the stream
- ******************************************************************************/
-
- void CWASTEDlgText::PutTo(CStream& stream)
- {
- #ifdef TCL_OBJECT_IO
- // write made up values
- stream << (long)0 << (Boolean) false << (Boolean) false;
- CWASTEText::PutTo(stream);
- #endif
- }
-
-
- /******************************************************************************
- GetFrom
-
- Get the contents of this object from the stream and
- initialize the object
- ******************************************************************************/
-
- void CWASTEDlgText::GetFrom(CStream& stream)
- {
- #ifdef TCL_OBJECT_IO
- Boolean required, validate;
- long maxValidLength;
-
- // note, values are ignored
- stream >> maxValidLength >> required >> validate;
-
- CWASTEText::GetFrom(stream);
- #endif
- }
-
- #endif // VA_COMPATIBLE_IO